<template>
	<view class="container">
		<view>
			<u-subsection :list="list" :current="current" mode="subsection" @change="change"></u-subsection>
		</view>
		<view v-for="(item, index) in tableData" :key="index" class="adviceBox">
			<uni-card :title="item.title" :extra="item.time" v-if="item.klassId==null" @click="AdviceInfo(index)">
				<u-read-more :showHeight="showHeight" toggle="true">
					<rich-text :nodes="item.content" style="color: #DDDDDD;"></rich-text>
				</u-read-more>
				<!-- <text class="uni-body">{{item.title}}</text> -->
			</uni-card>
			<uni-card :title="item.title" :extra="item.time" v-if="item.klassId!=null" @click="AdviceInfo(index)">
				<u-read-more :showHeight="showHeight" toggle="true">
					<rich-text :nodes="item.content" style="color: #DDDDDD;"></rich-text>
				</u-read-more>
			</uni-card>
<!-- 			<view class="title" style="display: flex;flex-direction：row;justify-content: space-between">
				<view style="display: flex;justify-content: space-between" class="title">{{item.title}}</view>
				<view style="display: flex;justify-content: space-between" class="time">{{item.time}}</view>
			</view> -->
<!-- 			<view>
				<view class="fontButton"
					style="display: flex;flex-direction：row;background-color: aliceblue;justify-content: space-between"
					@click="AdviceInfo(index)">
					<view style="display: flex;justify-content: space-between;padding: 10px;">通知详情</view>
					<view style="display: flex;justify-content: space-between;padding: 10px;color: #888888;">></view>
				</view>
			</view> -->
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				showHeight: 100,
				list: ['校园通知', '班级通知'],
				current: 0,
				header: '通知列表',
				isShow: false, // 是否清空已选项
				value: 0,
				range: [{
						value: 0,
						text: "全部消息"
					},
					{
						value: 1,
						text: "班级消息"
					},
				],
				tableData: [],
			};
		},
		onShow() {
			this.getAllAdvice();
		},
		methods: {
			changeAdviceType(e) {
				if (e == 0) {
					this.getAllAdvice();
				} else {
					this.getClassAdvice();
				}
			},
			AdviceInfo(row) {
				// 获取当前选中行的数据
				let result = this.tableData[row];
				// 页面跳转
				console.log(result.id);
				uni.navigateTo({
					url: '/pages/announcement/annDetail/annDetail?id=' + result.id,
				})
			},
			getAllAdvice() {
				this.$myReq({
						url: '/advice/api/getAll',
						method: 'get'
					})
					.then((res) => {
						//console.log(res.data)
						this.tableData = res.data
						// 处理标题超过10的通知
						for (let s of res.data) {
							if (s.title.length >= 11) {
								s.title = s.title.substring(0, 9);
								s.title = s.title + "...";
							}
						}
					})
			},
			getClassAdvice() {
				this.$myReq({
						url: '/advice/api/getClassAdvice',
						method: 'get'
					})
					.then((res) => {
						console.log(res.data)
						this.tableData = res.data
						// 处理标题超过10的通知
						for (let s of res.data) {
							if (s.title.length >= 11) {
								s.title = s.title.substring(0, 9);
								s.title = s.title + "...";
							}
						}
					})
			},
			change(index){
				this.current = index;
				if(this.current==0){
					this.getAllAdvice();
				}else{
					this.getClassAdvice();
				}
			}
		}
	}
</script>

<style>
	.adviceBox {
		border: 1px;
		margin-top: 10px;
		margin-bottom: 10px;
		background-color: #FFFFFF;
	}

	.title {
		font-size: 18px;
		color: #000000;
	}

	.content {
		font-size: 16px;
		width: 350px;
		color: #AAAAAA;
		margin: 10px;
		white-space: nowrap;
		text-overflow: ellipsis;
		display: inline-block;
		width: 95%;
		height: auto;
		font-family: Gibson;
		font-size: 32rpx;
		word-break: break-all;
		text-overflow: ellipsis;
		word-wrap: break-word;
		white-space: pre-wrap;
	}

	.time {
		color: #DDDDDD;
		font-size: 14px;
		padding-left: 120px;
	}

	.fontButton {
		margin-bottom: 20px;
	}
</style>
